package com.zhentao.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.zhentao.Main;
import com.zhentao.pojo.TbOrder;
import com.zhentao.service.TbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private TbOrderService service;
    @Autowired
    private Main main;
    @RequestMapping("add")
    public String add(Integer id,Integer num){
        TbOrder order=new TbOrder();
        order.setItemId(id);
        order.setNum(num);
        service.save(order);
        main.update(id,num);
        return "添加成功";
    }
    @RequestMapping("findOrder")
    @SentinelResource("findOrders")
    public Double findOrder(Integer id){
        TbOrder o = service.getById(id);
        Integer itemId = o.getItemId();
        Integer num = o.getNum();
        Double price = main.findPrice(itemId);
        System.err.println(price);
        return num*price;
    }
}
